#include "SsaoStage.h"
#include "ImageUtil.h"

namespace egg{

    SsaoStage::SsaoStage(){
        mQuad=gGeometryLib.getGeometry("quad");
        mShader=ShaderPtr(new Shader());
        mShader->fromFile("glsl/ssao.vs","glsl/ssao.fs");
        mParamMap.bindShader(mShader);
        mParamMap.bindNumericParam("uni_vec4_frustum");
        mParamMap.bindNumericParam("uni_mat4_projection");
        mParamMap.bindTextureParam("uni_sampler2D_gNormal");
        mParamMap.bindTextureParam("uni_sampler2D_gPosition");
    }

    void SsaoStage::doRender(const FrameEvent& evt,FrameBufferPtr gbuffer){
        StateCache::disableBlend();
        StateCache::disableDepthTest();
        StateCache::setDepthWrite(false);
        StateCache::setFillMode(GL_FILL);
        StateCache::enableCull(GL_CCW,GL_BACK);
        StateCache::enableStencilTest(GL_KEEP);
        glStencilFunc(GL_EQUAL,SM_OPACITY,SM_OPACITY);
        mParamMap._commitParamsForce();
        mQuad->draw();
    }


}